<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon32.ico?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon16.ico?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="编程,Java," />





  <link rel="alternate" href="/rss2.xml" title="老苏叶的小窝" type="application/atom+xml" />






<meta name="description" content="Java基础知识点梳理摘要：在经过这段时间对java的学习，但是一直没系统地对java这门语言进行梳理和总结，掌握的知识也比较零散。恰好利用这段时间重新认识下java，并对一些常见的语法和知识点做个总结与回顾，一方面为了加深印象，方便后面查阅，一方面为了学好java打下基础。 1.Java简介java语言于1995年正式推出，最开始被命名为Oak语言，由James Gosling（詹姆斯·高斯">
<meta property="og:type" content="article">
<meta property="og:title" content=" Java基础知识点梳理">
<meta property="og:url" content="https://gitee.com/laosuye/laosuye.git/2020/04/23/Java%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E7%82%B9%E6%A2%B3%E7%90%86/index.html">
<meta property="og:site_name" content="老苏叶的小窝">
<meta property="og:description" content="Java基础知识点梳理摘要：在经过这段时间对java的学习，但是一直没系统地对java这门语言进行梳理和总结，掌握的知识也比较零散。恰好利用这段时间重新认识下java，并对一些常见的语法和知识点做个总结与回顾，一方面为了加深印象，方便后面查阅，一方面为了学好java打下基础。 1.Java简介java语言于1995年正式推出，最开始被命名为Oak语言，由James Gosling（詹姆斯·高斯">
<meta property="og:image" content="https://gitee.com/laosuye/TC/raw/master/20200527000337.png">
<meta property="og:image" content="https://gitee.com/laosuye/TC/raw/master/20200527000423.png">
<meta property="og:image" content="https://gitee.com/laosuye/TC/raw/master/20200527000430.png">
<meta property="og:image" content="https://gitee.com/laosuye/TC/raw/master/20200527000437.png">
<meta property="og:image" content="https://gitee.com/laosuye/TC/raw/master/20200527000446.png">
<meta property="og:image" content="https://gitee.com/laosuye/TC/raw/master/20200527000454.png">
<meta property="og:image" content="https://gitee.com/laosuye/TC/raw/master/20200527000503.png">
<meta property="og:image" content="https://gitee.com/laosuye/TC/raw/master/20200527000509.png">
<meta property="og:image" content="https://gitee.com/laosuye/TC/raw/master/20200527000553.png">
<meta property="og:image" content="https://gitee.com/laosuye/TC/raw/master/20200527000606.png">
<meta property="og:image" content="https://gitee.com/laosuye/TC/raw/master/20200527000626.png">
<meta property="og:image" content="https://gitee.com/laosuye/TC/raw/master/20200527000639.png">
<meta property="og:image" content="https://gitee.com/laosuye/TC/raw/master/20200527000647.png">
<meta property="og:image" content="https://gitee.com/laosuye/TC/raw/master/20200527000655.png">
<meta property="og:image" content="https://gitee.com/laosuye/TC/raw/master/20200527000703.png">
<meta property="og:image" content="https://gitee.com/laosuye/TC/raw/master/20200527000715.png">
<meta property="og:image" content="https://gitee.com/laosuye/TC/raw/master/20200527000726.png">
<meta property="article:published_time" content="2020-04-23T14:40:54.000Z">
<meta property="article:modified_time" content="2024-06-20T01:37:42.000Z">
<meta property="article:author" content="老苏叶">
<meta property="article:tag" content="编程">
<meta property="article:tag" content="Java">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/laosuye/TC/raw/master/20200527000337.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"right","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://gitee.com/laosuye/laosuye.git/2020/04/23/Java基础知识点梳理/"/>





  <title> Java基础知识点梳理 | 老苏叶的小窝</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?e8f796a0dc919d18055bb061f82a6395";";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




<meta name="generator" content="Hexo 4.2.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-right page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">老苏叶的小窝</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/laosuye/laosuye.git/2020/04/23/Java%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E7%82%B9%E6%A2%B3%E7%90%86/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="老苏叶">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatra.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="老苏叶的小窝">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline"> Java基础知识点梳理</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-04-23T22:40:54+08:00">
                2020-04-23
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%BC%96%E7%A8%8B/" itemprop="url" rel="index">
                    <span itemprop="name">编程</span>
                  </a>
                </span>

                
                
                  ， 
                
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%BC%96%E7%A8%8B/%E7%BC%96%E7%A8%8B%E5%9F%BA%E7%A1%80/" itemprop="url" rel="index">
                    <span itemprop="name">编程基础</span>
                  </a>
                </span>

                
                
                  ， 
                
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%BC%96%E7%A8%8B/%E7%BC%96%E7%A8%8B%E5%9F%BA%E7%A1%80/Java/" itemprop="url" rel="index">
                    <span itemprop="name">Java</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2020/04/23/Java%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E7%82%B9%E6%A2%B3%E7%90%86/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2020/04/23/Java%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E7%82%B9%E6%A2%B3%E7%90%86/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i> 浏览
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>次
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  5k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长"> 分钟
                  19
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <meta name="referrer" content="no-referrer">

<h1 id="Java基础知识点梳理"><a href="#Java基础知识点梳理" class="headerlink" title="Java基础知识点梳理"></a>Java基础知识点梳理</h1><h2 id="摘要："><a href="#摘要：" class="headerlink" title="摘要："></a>摘要：</h2><p>在经过这段时间对java的学习，但是一直没系统地对java这门语言进行梳理和总结，掌握的知识也比较零散。恰好利用这段时间重新认识下java，并对一些常见的语法和知识点做个总结与回顾，一方面为了加深印象，方便后面查阅，一方面为了学好java打下基础。</p>
<h2 id="1-Java简介"><a href="#1-Java简介" class="headerlink" title="1.Java简介"></a>1.Java简介</h2><p>java语言于1995年正式推出，最开始被命名为Oak语言，由James Gosling（詹姆斯·高斯林）在Sun Microsystems公司和同事共同研发，Microsystems如今已经被oracle收购。java语言具有以下特点：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">简单性</span><br><span class="line">面向对象</span><br><span class="line">可移植性</span><br><span class="line">安全性</span><br><span class="line">健壮性</span><br><span class="line">多线程</span><br></pre></td></tr></table></figure>

<h2 id="2-Java文件运行过程如下："><a href="#2-Java文件运行过程如下：" class="headerlink" title="2.Java文件运行过程如下："></a>2.Java文件运行过程如下：</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">1.编写源代码，文件格式： .java</span><br><span class="line">2.编译 .java文件 生成.class文件（二进制字节码文件）</span><br><span class="line">3.运行 .class文件在JVM上(java虚拟机，支持多平台)</span><br></pre></td></tr></table></figure>

<h2 id="3-Java语言基础语法"><a href="#3-Java语言基础语法" class="headerlink" title="3.Java语言基础语法"></a>3.Java语言基础语法</h2><h3 id="1-注释"><a href="#1-注释" class="headerlink" title="1.注释"></a>1.注释</h3><p>注释用于解释程序，增强可读性，java中注释有以下几种:</p>
<h4 id="1-单行注释，语法如下："><a href="#1-单行注释，语法如下：" class="headerlink" title="1.单行注释，语法如下："></a>1.单行注释，语法如下：</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 单行注释</span><br></pre></td></tr></table></figure>

<h4 id="2-多行注释，语法如下："><a href="#2-多行注释，语法如下：" class="headerlink" title="2.多行注释，语法如下："></a>2.多行注释，语法如下：</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;*</span><br><span class="line">多行注释</span><br><span class="line">多行注释</span><br><span class="line">*&#x2F;</span><br></pre></td></tr></table></figure>

<h4 id="3-javadoc注释，是一种专业注释，可以被javadoc-exe工具解析提取生成帮助文档"><a href="#3-javadoc注释，是一种专业注释，可以被javadoc-exe工具解析提取生成帮助文档" class="headerlink" title="3.javadoc注释，是一种专业注释，可以被javadoc.exe工具解析提取生成帮助文档"></a>3.javadoc注释，是一种专业注释，可以被javadoc.exe工具解析提取生成帮助文档</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;**</span><br><span class="line">javadoc注释</span><br><span class="line">*&#x2F;</span><br></pre></td></tr></table></figure>

<h3 id="2-标识符"><a href="#2-标识符" class="headerlink" title="2.标识符"></a>2.标识符</h3><p>标识符用于标识类名，方法名，变量名，接口名等，命名需要满足以下规则：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">只能由&quot;数字，字母（A-Z 或者 a-z）,美元符（$）、或者下划线（）&quot;组成 所有的标识符都应该以字母（A-Z 或者 a-z）,美元符（$）、或者下划线（）开始</span><br><span class="line">严格区分大小写，不能用关键字做标识符</span><br></pre></td></tr></table></figure>

<p>java编程规范建议遵守驼峰命名法，类名和接口名首字母大写，变量和方法名首字母小写。Java采用unicode的编码方式，所以标识符也支持中文。</p>
<h3 id="3-类的定义"><a href="#3-类的定义" class="headerlink" title="3.类的定义"></a>3.类的定义</h3><p>java定义一个类用class关键字，有以下几点需要注意：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">一个java源文件定义公开的类只能有一个，类名称必须和java源文件名称一致</span><br><span class="line">一个java源文件可以编写多个class</span><br><span class="line">每一个class都可以编写main方法</span><br></pre></td></tr></table></figure>

<h2 id="4-Java数据类型"><a href="#4-Java数据类型" class="headerlink" title="4.Java数据类型"></a>4.Java数据类型</h2><h4 id="1-基本数据类型"><a href="#1-基本数据类型" class="headerlink" title="1.基本数据类型"></a>1.基本数据类型</h4><p>数据类型的作用是指导JVM在运行程序的时候给该数据分配多大的内存空间，Java提供了以下八种基础数据类型：</p>
<p><img src="https://gitee.com/laosuye/TC/raw/master/20200527000337.png" alt></p>
<h4 id="2-整型表示方式"><a href="#2-整型表示方式" class="headerlink" title="2.整型表示方式"></a>2.整型表示方式</h4><p>整型有三种表示方式，默认是十进制：</p>
<p><img src="https://gitee.com/laosuye/TC/raw/master/20200527000423.png" alt></p>
<h4 id="3-类型转换"><a href="#3-类型转换" class="headerlink" title="3.类型转换"></a>3.类型转换</h4><p>类型转换有如下规则：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">1.八种基本数据类型除了布尔类型之外，剩下的7种类型都可以互相转换</span><br><span class="line">2.小容量向大容量转换，可以自动进行，容量从小到大排序为：</span><br><span class="line">byte &lt; short &lt; int &lt; long &lt; float &lt; double</span><br><span class="line">3.大容量数据转换成小容量，需要进行强制类型转换，强转会损失精度</span><br><span class="line">4.byte, short ,char 混合运算，各自转换成int；多种数据类型混合运算，转换成容量最大的类型再运算。</span><br></pre></td></tr></table></figure>

<p>对于强制类型转换，将long强转成int的语法如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">long k &#x3D; 6475201314L;</span><br><span class="line">int num &#x3D; (int) k;</span><br></pre></td></tr></table></figure>

<p>注意：大容量转换成小容量编译无法通过，比如下面代码无法编译：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">byte b &#x3D; 19;</span><br><span class="line">b &#x3D; b + 13; &#x2F;&#x2F; 相当于直接把整型赋值给byte型，报错</span><br><span class="line">b +&#x3D; 13; &#x2F;&#x2F; 可以编译，等同于 b &#x3D; (byte)(b + 13)</span><br></pre></td></tr></table></figure>

<h4 id="4-复合数据类型"><a href="#4-复合数据类型" class="headerlink" title="4.复合数据类型"></a>4.复合数据类型</h4><h5 id="1-字符串-String"><a href="#1-字符串-String" class="headerlink" title="1.字符串(String)"></a>1.字符串(String)</h5><p>在Java中使用String 类来创建和操作字符串，初始化一个String的语法如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 常用，用双引号直接创建</span><br><span class="line">String testStr &#x3D; &quot;Wasting time is robbing oneself&quot;;</span><br><span class="line">&#x2F;&#x2F; 不常用，使用char数组创建</span><br><span class="line">char[] helloArray &#x3D; &#123;&#39;h&#39;, &#39;e&#39;, &#39;l&#39;, &#39;l&#39;, &#39;o&#39;&#125;;</span><br><span class="line">String helloString &#x3D; new String(helloArray);</span><br></pre></td></tr></table></figure>

<p>由于字符串使用非常频繁，String类也提供了很多方法，下面介绍一些用的比较多的。</p>
<h6 id="1-对字符串进行修改的常用方法有-包括格式化，大小写转换-："><a href="#1-对字符串进行修改的常用方法有-包括格式化，大小写转换-：" class="headerlink" title="1.对字符串进行修改的常用方法有(包括格式化，大小写转换)："></a>1.对字符串进行修改的常用方法有(包括格式化，大小写转换)：</h6><p><img src="https://gitee.com/laosuye/TC/raw/master/20200527000430.png" alt></p>
<h6 id="2-对字符串进行查找和替换的方法有："><a href="#2-对字符串进行查找和替换的方法有：" class="headerlink" title="2.对字符串进行查找和替换的方法有："></a>2.对字符串进行查找和替换的方法有：</h6><p><img src="https://gitee.com/laosuye/TC/raw/master/20200527000437.png" alt></p>
<p>获取子字符串的常用方法有：</p>
<p><img src="https://gitee.com/laosuye/TC/raw/master/20200527000446.png" alt></p>
<h6 id="3-对字符串进行比较的方法有："><a href="#3-对字符串进行比较的方法有：" class="headerlink" title="3.对字符串进行比较的方法有："></a>3.对字符串进行比较的方法有：</h6><p><img src="https://gitee.com/laosuye/TC/raw/master/20200527000454.png" alt></p>
<h6 id="4-其他常见的方法比如统计长度，拼接，转换等："><a href="#4-其他常见的方法比如统计长度，拼接，转换等：" class="headerlink" title="4.其他常见的方法比如统计长度，拼接，转换等："></a>4.其他常见的方法比如统计长度，拼接，转换等：</h6><p><img src="https://gitee.com/laosuye/TC/raw/master/20200527000503.png" alt></p>
<h5 id="2-数组"><a href="#2-数组" class="headerlink" title="2.数组"></a>2.数组</h5><h6 id="1-数组可以用于存放固定大小的同类型元素，声明一个数组的语法如下："><a href="#1-数组可以用于存放固定大小的同类型元素，声明一个数组的语法如下：" class="headerlink" title="1.数组可以用于存放固定大小的同类型元素，声明一个数组的语法如下："></a>1.数组可以用于存放固定大小的同类型元素，声明一个数组的语法如下：</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">变量类型[] 数组名;</span><br></pre></td></tr></table></figure>

<h6 id="2-创建数组的语法："><a href="#2-创建数组的语法：" class="headerlink" title="2.创建数组的语法："></a>2.创建数组的语法：</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">数组名 &#x3D; new 变量类型[数组大小];</span><br><span class="line">变量类型[] 数组名 &#x3D; &#123;value0, value1, …, valuek&#125;;</span><br></pre></td></tr></table></figure>

<h6 id="3-数组的变量类型可以是前面介绍八种基本数据类型以及复合数据类型，“数组名-索引-”-可以访问数组元素，下面是一个操作一维数组例子："><a href="#3-数组的变量类型可以是前面介绍八种基本数据类型以及复合数据类型，“数组名-索引-”-可以访问数组元素，下面是一个操作一维数组例子：" class="headerlink" title="3.数组的变量类型可以是前面介绍八种基本数据类型以及复合数据类型，“数组名[索引]” 可以访问数组元素，下面是一个操作一维数组例子："></a>3.数组的变量类型可以是前面介绍八种基本数据类型以及复合数据类型，“数组名[索引]” 可以访问数组元素，下面是一个操作一维数组例子：</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">int[] primeNumbers &#x3D; &#123;2, 3, 5, 7, 11, 13, 17, 19, 23, 29&#125;;</span><br><span class="line"> for (int num : primeNumbers) &#123;</span><br><span class="line">     System.out.println(&quot;num: &quot; + num);</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>

<h6 id="4-操作二维数组的例子如下："><a href="#4-操作二维数组的例子如下：" class="headerlink" title="4.操作二维数组的例子如下："></a>4.操作二维数组的例子如下：</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">int[][] a &#x3D; new int[2][3];</span><br><span class="line">a[0][0] &#x3D; 19;</span><br><span class="line">String[][] s &#x3D; new String[2][];</span><br><span class="line">s[0] &#x3D; new String[2]; &#x2F;&#x2F; 第一个数组长度为2</span><br><span class="line">s[1] &#x3D; new String[3]; &#x2F;&#x2F; 第二个数组长度为3</span><br><span class="line">s[0][0] &#x3D; &quot;Hello&quot;;</span><br><span class="line">s[0][1] &#x3D; &quot;World&quot;;</span><br></pre></td></tr></table></figure>

<h6 id="5-java-util-Arrays类能方便地操作数组，它提供的所有方法都是静态的，比较常见的方法有："><a href="#5-java-util-Arrays类能方便地操作数组，它提供的所有方法都是静态的，比较常见的方法有：" class="headerlink" title="5.java.util.Arrays类能方便地操作数组，它提供的所有方法都是静态的，比较常见的方法有："></a>5.java.util.Arrays类能方便地操作数组，它提供的所有方法都是静态的，比较常见的方法有：</h6><p><img src="https://gitee.com/laosuye/TC/raw/master/20200527000509.png" alt></p>
<h6 id="6-使用Arrays的sort方法进行排序的例子如下："><a href="#6-使用Arrays的sort方法进行排序的例子如下：" class="headerlink" title="6.使用Arrays的sort方法进行排序的例子如下："></a>6.使用Arrays的sort方法进行排序的例子如下：</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">int[] primeNumbers &#x3D; &#123;7, 11, 5, 2, 3&#125;;</span><br><span class="line"> Arrays.sort(primeNumbers);</span><br><span class="line"> for (int num : primeNumbers) &#123;</span><br><span class="line">     System.out.println(&quot;num: &quot; + num);</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>

<h5 id="3-集合"><a href="#3-集合" class="headerlink" title="3.集合"></a>3.集合</h5><p>Java语言提供了一个完善的集合框架，主要包括两种类型的容器，一种是集合（Collection），存储一个元素集合，另一种是图（Map），存储键/值对映射<br>经常用到的集合有：</p>
<p><img src="https://gitee.com/laosuye/TC/raw/master/20200527000553.png" alt></p>
<p>ArrayList提供的常用方法有：</p>
<p><img src="https://gitee.com/laosuye/TC/raw/master/20200527000606.png" alt></p>
<p>下面是操作一个java.util.ArrayList的例子:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">ArrayList list &#x3D; new ArrayList();</span><br><span class="line">list.add(2);</span><br><span class="line">list.add(3);</span><br><span class="line">list.add(5);</span><br><span class="line">for (int i &#x3D; 0; i&lt;list.size(); i++) &#123;</span><br><span class="line">    System.out.println(list.get(i));</span><br><span class="line">&#125;</span><br><span class="line">list.remove(1);</span><br><span class="line">list.set(1, 19);</span><br></pre></td></tr></table></figure>

<h5 id="4-类型转换方法"><a href="#4-类型转换方法" class="headerlink" title="4.类型转换方法"></a>4.类型转换方法</h5><p>关于数据类型，最后再介绍下Java中常见的类型转换方法：</p>
<p><img src="https://gitee.com/laosuye/TC/raw/master/20200527000626.png" alt></p>
<h4 id="5-运算符"><a href="#5-运算符" class="headerlink" title="5.运算符"></a>5.运算符</h4><p>Java的运算符种类比较多，本文介绍几种常见的运算符：</p>
<h5 id="1-算术运算符"><a href="#1-算术运算符" class="headerlink" title="1.算术运算符"></a>1.算术运算符</h5><p>java的算术运算符如下表(int a = 10; int b= 9;):</p>
<p><img src="https://gitee.com/laosuye/TC/raw/master/20200527000639.png" alt></p>
<p>基本的赋值运算符”=” 可以与前5种算术运算符组合成 +=,-=,*=,/=,%=等扩展的赋值运算符<br>int a = 10; a += 5； 等价于 a = (int)(a + 5)；<br>其他的运算符类似，扩展运算符默认有类型转换，但是不改变运算结果类型</p>
<p>对于”+”运算符，只要两边的操作数有一个是字符串就会进行字符串连接运算生成一个新的字符串。</p>
<h5 id="2-关系运算符"><a href="#2-关系运算符" class="headerlink" title="2.关系运算符"></a>2.关系运算符</h5><p>java中主要有以下六种关系运算符：</p>
<p><img src="https://gitee.com/laosuye/TC/raw/master/20200527000647.png" alt></p>
<p>关系运算符返回的结果是布尔型</p>
<h5 id="3-逻辑运算符"><a href="#3-逻辑运算符" class="headerlink" title="3.逻辑运算符"></a>3.逻辑运算符</h5><p>主要有以下三种逻辑运算符（boolean a = true; boolean b = false）：</p>
<p><img src="https://gitee.com/laosuye/TC/raw/master/20200527000655.png" alt></p>
<h5 id="4-位运算符"><a href="#4-位运算符" class="headerlink" title="4.位运算符"></a>4.位运算符</h5><p>位运算符对两个操作数的每一位进行运算，有以下几种常见的类型：</p>
<p><img src="https://gitee.com/laosuye/TC/raw/master/20200527000703.png" alt></p>
<h5 id="5-三目运算符"><a href="#5-三目运算符" class="headerlink" title="5.三目运算符"></a>5.三目运算符</h5><p>三目元素符的语法规则：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">布尔表达式 ? 表达式1 : 表达式2;</span><br></pre></td></tr></table></figure>

<p>布尔表达式为真执行表达式1，为假执行表达式2，利用三目运算符求最大值的一个例子如下：</p>
<h4 id="6-控制语句"><a href="#6-控制语句" class="headerlink" title="6.控制语句"></a>6.控制语句</h4><p>每种编程语言都少不了控制语句来控制代码流程，java语言也提供了丰富的控制语句。</p>
<h5 id="1-选择结构"><a href="#1-选择结构" class="headerlink" title="1.选择结构"></a>1.选择结构</h5><h6 id="1-if语句"><a href="#1-if语句" class="headerlink" title="1.if语句"></a>1.if语句</h6><p>if语句常见的语法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 第一种写法，else分支可以省略</span><br><span class="line"> if (布尔表达式) &#123;</span><br><span class="line">     表达式为真要执行的语句;</span><br><span class="line"> &#125; else &#123;</span><br><span class="line">     其他条件要执行的语句</span><br><span class="line"> &#125;</span><br><span class="line"> &#x2F;&#x2F; 第二种写法，最后的else分支可以省略</span><br><span class="line"> if (布尔表达式) &#123;</span><br><span class="line">     表达式为真要执行的语句;</span><br><span class="line"> &#125; else if (布尔表达式1) &#123;</span><br><span class="line">     表达式1为真要执行的语句</span><br><span class="line"> &#125; else if (布尔表达式2) &#123;</span><br><span class="line">     表达式2为真要执行的语句</span><br><span class="line"> &#125; else &#123;</span><br><span class="line">     除上述条件之外要执行的语句</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>

<h6 id="2-switch语句"><a href="#2-switch语句" class="headerlink" title="2.switch语句"></a>2.switch语句</h6><p>switch语句的语法如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">switch (expression) &#123;</span><br><span class="line">     case value1 :</span><br><span class="line">        &#x2F;&#x2F; 匹配value1成功之后执行的语句</span><br><span class="line">        break; &#x2F;&#x2F; 可选</span><br><span class="line">     case value2 :</span><br><span class="line">        &#x2F;&#x2F; 匹配value2成功之后执行的语句</span><br><span class="line">        break; &#x2F;&#x2F;可选</span><br><span class="line">     …</span><br><span class="line">     default : &#x2F;&#x2F; 可选</span><br><span class="line">        &#x2F;&#x2F; 前面case分支都没匹配时执行的语句</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>

<p>其中expression支持byte、short、int、char以及字符串(String)，byte、short、char会转换为int类型。程序只有遇到break语句才会跳出switch语句，缺少break的分支会继续往下面分支执行。</p>
<h5 id="2-循环结构"><a href="#2-循环结构" class="headerlink" title="2.循环结构"></a>2.循环结构</h5><p>程序当中总会有些需要重复执行的代码片段，因此各个编程语言都支持循环语法。</p>
<h6 id="1-for语句"><a href="#1-for语句" class="headerlink" title="1.for语句"></a>1.for语句</h6><p>for语句的语法如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">for (初始化表达式; 布尔表达式; 更新表达式) &#123;    </span><br><span class="line">      &#x2F;&#x2F; 要重复执行的代码片段 &#125;</span><br></pre></td></tr></table></figure>

<p>执行过程：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">1. 初始化表达式最先执行而且只执行一次；</span><br><span class="line">2.判断布尔表达式，如果是真执行循环体，如果是假则退出循环</span><br><span class="line">3.循环体执行之后更新表达式，再执行步骤2，反复循环直到退出循环</span><br><span class="line">利用for循环计算数字1到10的和的代码如下：</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">int sum &#x3D; 0;</span><br><span class="line"> for (int i &#x3D; 0; i &lt;&#x3D; 10; i++) &#123;</span><br><span class="line">     sum +&#x3D; i;</span><br><span class="line"> &#125;</span><br><span class="line"> System.out.println(&quot;the sum is: &quot; + sum);</span><br></pre></td></tr></table></figure>

<h6 id="2-while语句"><a href="#2-while语句" class="headerlink" title="2.while语句"></a>2.while语句</h6><p>while语句的语法如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">while (布尔表达式) &#123;</span><br><span class="line">   &#x2F;&#x2F; 循环内容</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>

<p>执行过程:<br>先判断布尔表达式的值，为真就执行循环体，为假则循环结束，循环体可能一次也不执行。<br>使用while循环计算数字1到10的和是：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">int sum &#x3D; 0;</span><br><span class="line"> int i &#x3D; 0;</span><br><span class="line"> while (i &lt;&#x3D;10) &#123;</span><br><span class="line">     sum +&#x3D; i;</span><br><span class="line">     i++;</span><br><span class="line"> &#125;</span><br><span class="line"> System.out.println(&quot;The sum is: &quot; + sum);</span><br></pre></td></tr></table></figure>

<h6 id="3-do…while-循环"><a href="#3-do…while-循环" class="headerlink" title="3.do…while 循环"></a>3.do…while 循环</h6><p>do…while循环的语法如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">do &#123;</span><br><span class="line">     &#x2F;&#x2F; 循环内容</span><br><span class="line"> &#125; while (布尔表达式);</span><br></pre></td></tr></table></figure>

<p>do…while循环先执行循环内容再判断表达式，循环体至少会执行一次。</p>
<h4 id="7-控制循环语句"><a href="#7-控制循环语句" class="headerlink" title="7.控制循环语句"></a>7.控制循环语句</h4><h5 id="1-break语句"><a href="#1-break语句" class="headerlink" title="1.break语句"></a>1.break语句</h5><p>break使用在switch语句中终止switch执行，使用在循环语句中终止循环，跳出当前循环体。语法如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">break;</span><br></pre></td></tr></table></figure>

<h5 id="2-continue语句"><a href="#2-continue语句" class="headerlink" title="2.continue语句"></a>2.continue语句</h5><p>continue表示直接进入下一次循环继续执行，语法如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">continue;</span><br></pre></td></tr></table></figure>

<h2 id="5-Java变量类型"><a href="#5-Java变量类型" class="headerlink" title="5.Java变量类型"></a>5.Java变量类型</h2><p>在Java中，所有的变量在使用前必须声明。声明变量的基本格式如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">type identifier &#x3D; value;</span><br><span class="line"> 1</span><br><span class="line">value的数据类型必须和声明的变量类型一致，变量的值可变化，必须先声明再赋值才能访问。</span><br></pre></td></tr></table></figure>

<h4 id="1-局部变量："><a href="#1-局部变量：" class="headerlink" title="1.局部变量："></a>1.局部变量：</h4><p>java中的局部变量声明在方法内部，有以下特点：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">变量只在作用域内有效，超出作用域变量将会被销毁；</span><br><span class="line">变量是在栈上分配，没有默认值，所以局部变量被声明后，必须经过初始化，才可以使用。</span><br><span class="line">局部变量存储在栈内存中。</span><br></pre></td></tr></table></figure>

<h4 id="2-实例变量-成员变量-："><a href="#2-实例变量-成员变量-：" class="headerlink" title="2.实例变量(成员变量)："></a>2.实例变量(成员变量)：</h4><p>成员变量在方法体之外声明，有以下特点：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">当一个对象被实例化之后，每个实例变量的值就跟着确定</span><br><span class="line">实例变量在对象创建的时候创建，在对象被销毁的时候销毁</span><br><span class="line">实例变量具有默认值，数值型变量的默认值是0，布尔型变量的默认值是false，引用类型变 量的默认值是null。</span><br><span class="line">成员变量在JVM的堆内存中存储，垃圾回收器主要针对堆内存处理。</span><br></pre></td></tr></table></figure>

<h4 id="3-静态变量："><a href="#3-静态变量：" class="headerlink" title="3.静态变量："></a>3.静态变量：</h4><p>静态变量用static关键字声明，需要记住以下特点：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">无论一个类创建了多少个对象，类只拥有静态变量的一份拷贝</span><br><span class="line">静态变量在第一次被访问时创建，在程序结束时销毁。</span><br><span class="line">静态变量具有默认值，取值和实例变量类似</span><br></pre></td></tr></table></figure>

<h4 id="4-不同类型变量在JVM中的存储情况如下表："><a href="#4-不同类型变量在JVM中的存储情况如下表：" class="headerlink" title="4.不同类型变量在JVM中的存储情况如下表："></a>4.不同类型变量在JVM中的存储情况如下表：</h4><p><img src="https://gitee.com/laosuye/TC/raw/master/20200527000715.png" alt></p>
<h5 id="1-方法-函数"><a href="#1-方法-函数" class="headerlink" title="1.方法/函数"></a>1.方法/函数</h5><h6 id="1-方法语法"><a href="#1-方法语法" class="headerlink" title="1.方法语法"></a>1.方法语法</h6><p>方法实质就是一段可以重复使用，完成某项特定功能的片段，和C语言中的函数类似。方法的语法如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[修饰符] 返回值类型 方法名(参数类型 参数名1, 参数类型 参数名2 …) &#123;</span><br><span class="line">     …</span><br><span class="line">     方法体;</span><br><span class="line">     …</span><br><span class="line">     return 返回值; &#x2F;&#x2F; 可选，与返回值类型一致</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>

<p>比如常见的main方法如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">public static void main(String []args) &#123;</span><br><span class="line">     System.out.println(&quot;Hello World!&quot;);</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>

<p>方法有如下几个部分组成：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">1.修饰符：修饰符，这是可选的，定义了该方法的访问类型。比如public, static, private, protected等</span><br><span class="line">2.返回值类型 ：方法可能会返回值，支持前面介绍的八种基本数据类型以及String，如果不需要返回值，返回值类型就写成void。</span><br><span class="line">3.方法名：是方法的实际名称，建议首字母小写。方法名和参数表共同构成方法签名。</span><br><span class="line">4.参数类型：即形参列表，形参的个数可以是：0~N个。当方法被调用时，传递值给对应参数，这个值被称为实参。</span><br><span class="line">5.方法体：方法体包含具体的语句，定义该方法的功能。</span><br><span class="line"> 下面是实现判断一个正整数是否是质数的函数的例子(假设num大于2)：</span><br><span class="line"> private static boolean isPrimeNumber(int num) &#123;</span><br><span class="line">     boolean isPrime &#x3D; true;</span><br><span class="line">     for (int i &#x3D; 2; i &lt; num; i++) &#123;</span><br><span class="line">         if (num % i &#x3D;&#x3D; 0) &#123;</span><br><span class="line">             isPrime &#x3D; false;</span><br><span class="line">             break;</span><br><span class="line">         &#125;</span><br><span class="line">     &#125;</span><br><span class="line">     return isPrime;</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>

<h5 id="2-方法内存"><a href="#2-方法内存" class="headerlink" title="2.方法内存"></a>2.方法内存</h5><p>方法代码片段属于.class字节码文件的一部分，在调用方法的时候才会在栈中分配内存，称为压栈；方法执行结束释放方法的内存空间称为弹栈。方法执行完之后，方法内局部变量的空间也释放，因此局部变量只在方法内有效。JVM的栈中主要存储的是局部变量。</p>
<h5 id="3-方法重载"><a href="#3-方法重载" class="headerlink" title="3.方法重载"></a>3.方法重载</h5><p>方法重载(overload)主要是是指方法名相同，参数列表不同，和返回值类型无关，和修饰符无关。要构成方法重载需要满足以下条件：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">方法是在同一个类当中</span><br><span class="line">这些方法的方法名相同</span><br><span class="line">参数列表不同，可以是数量不同，顺序不同，类型不同</span><br></pre></td></tr></table></figure>

<h2 id="6-面向对象"><a href="#6-面向对象" class="headerlink" title="6.面向对象"></a>6.面向对象</h2><p>面向对象是Java核心的特点，主要有以下特性：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">封装：封装就是隐藏实现细节，仅对外提供访问接口。优点是使代码模块化，具有安全性。</span><br><span class="line">继承：继承就是将已存在的类(父类)的定义作为基础建立新类，新类(子类)的定义可以增加新的数据或新的功能，也可以用父类的功能</span><br><span class="line">多态：多态就是引用变量指向的具体类型和通过该引用变量发出的方法调用在编程时并不确定，而是在程序运行期间才确定。使得程序灵活地运行在多个状态。</span><br><span class="line">对象和类的定义：</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">对象(object)：对象是类的一个实例，是实际存在的个体，有状态和行为。</span><br><span class="line">类(class)：类是一个模板，它描述一类对象的行为和状态，是抽象思考的结果。</span><br><span class="line">对象和类的关系：</span><br><span class="line">一个类进行实例化就形成了对象，对象抽象形成类。</span><br></pre></td></tr></table></figure>

<p>类的语法如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[修饰符列表] class 类名 &#123;</span><br><span class="line">     属性; &#x2F;&#x2F; 对象的状态信息，通常采用变量方式定义，称为成员变量</span><br><span class="line">     方法; &#x2F;&#x2F; 对象的动作信息</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>

<p>类实例化需要用<strong>new</strong>运算符，语法如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">new 类名();</span><br></pre></td></tr></table></figure>

<p>java中的类属于引用数据类型，new新建的java对象存储在JVM的堆内存中，new等号左侧类的变量名存储的是指向堆内存的地址。每个new出来的类的内存互相独立。<br>Java面向对象中相关的重要知识点有：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">构造方法：构造方法名称与类名相同，无返回参数。构造方法在类初始化的时候调用，支持重载。类存在默认的无参构造方法。</span><br><span class="line">this关键字：this指向当前对象的引用，&quot;this.属性名称&quot;或者&quot;this.方法名称&quot;用于访问本类的变量或者方法，在构造方法中使用&quot;this();&quot;语句访问本类的构造方法。</span><br><span class="line">static关键字：static修饰属性表示静态变量，修饰类的方法表明无需类的对象就可以调用此方法。</span><br><span class="line">super关键字：super为对父类的引用，可以使用super来调用父类的属性，方法，和构造方法。</span><br><span class="line">final关键字：final修饰变量表示变量的值初始化后不能发生变化；final修饰方法表示不能被子类重写；final修饰的类无法被继承。</span><br><span class="line">抽象类：抽象类使用abstract关键字声明，非抽象类继承抽象类必须实现所有抽象方法，抽象类不能被实例化。抽象类不能声明为final。</span><br><span class="line">instanceof关键字：instanceof 是用于检查对象是否为指定的类型，通常在进行类型转换时要使用，以避免发生类型转换异常。</span><br><span class="line">接口(Interface)：接口是一个抽象类型，是抽象方法的集合。接口不是类，接口没有构造方法，不能被实例化，只能被类实现。接口只能包含 static 和 final 变量。</span><br></pre></td></tr></table></figure>

<p>Java中声明一个接口的语法如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">interface 接口名称 [extends 其他的接口名] &#123;</span><br><span class="line"> 　　全局常量;</span><br><span class="line"> 　　抽象方法;</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>

<h2 id="7-常用函数"><a href="#7-常用函数" class="headerlink" title="7.常用函数"></a>7.常用函数</h2><p>接着介绍Java中使用非常频繁的几个函数：</p>
<h4 id="1-输出函数"><a href="#1-输出函数" class="headerlink" title="1.输出函数"></a>1.输出函数</h4><p>控制台的输出由 print() 和 println() 完成。这些方法都由类 PrintStream 定义，System.out 是该类对象的一个引用。print()打印指定的字符不换行，println()打印完成换一行。<br>下面是使用的例子</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">System.out.print(&quot;Remember: &quot;);</span><br><span class="line">System.out.println(&quot;Haste makes waste&quot;);</span><br></pre></td></tr></table></figure>

<h4 id="2-输入函数"><a href="#2-输入函数" class="headerlink" title="2.输入函数"></a>2.输入函数</h4><p>Java中使用java.util.Scanner类获取用户的输入，使用前需要先创建Scanner对象。常用next() 与 nextLine() 方法获取输入的字符串，对应地用hasNext() 与 hasNextLine() 判断是否还有输入的数据。<br>下面是使用next函数获取用户输入字符串的例子：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 创建scanner对象</span><br><span class="line"> Scanner scan &#x3D; new Scanner(System.in);</span><br><span class="line"> &#x2F;&#x2F; 判断是否还有输入</span><br><span class="line"> if (scan.hasNext()) &#123;</span><br><span class="line">     String inputStr &#x3D; scan.next();</span><br><span class="line">     System.out.println(&quot;you input：&quot; + inputStr);</span><br><span class="line"> &#125;</span><br><span class="line"> &#x2F;&#x2F; 关闭scanner</span><br><span class="line"> scan.close();</span><br></pre></td></tr></table></figure>

<p>还可以使用nextInt接收一个整数，Scanner常用的方法如下表：</p>
<p><img src="https://gitee.com/laosuye/TC/raw/master/20200527000726.png" alt></p>
<h2 id="8-总结"><a href="#8-总结" class="headerlink" title="8.总结"></a>8.总结</h2><p>Java这门语言涵盖的知识点比较丰富，一篇文章是不可能将所有知识点都完全覆盖到的。本文的主要目的是梳理下基础常见的知识点，帮助大家一起复习下，学习一门语言打好基础是至关重要的。掌握了这些基础知识点，自己动手写一些小程序问题也不大。文章最后再附上一个完整代码的小例子，实现的功能是将用户输入的字符串逆序输出</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">class Test&#123; </span><br><span class="line">public static void main(String args[]) &#123;</span><br><span class="line">Scanner scan &#x3D; new Scanner(System.in);</span><br><span class="line"></span><br><span class="line">class Test&#123;  </span><br><span class="line">     public static void main(String args[]) &#123;</span><br><span class="line">     			Scanner scan &#x3D; new Scanner(System.in);</span><br><span class="line">    				 String inputStr &#x3D; scan.nextLine();         &#x2F;&#x2F; String转换为char数组         </span><br><span class="line">    					 char[] nums &#x3D; inputStr.toCharArray();         </span><br><span class="line">     				for (int i &#x3D; nums.length; i&gt;0; i--) &#123;             </span><br><span class="line">     		System.out.print(nums[i-1]);         </span><br><span class="line">     &#125;         </span><br><span class="line">     System.out.println(&quot;&quot;);  &#125;</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>

<h2 id="9-参考文献"><a href="#9-参考文献" class="headerlink" title="9.参考文献"></a>9.参考文献</h2><p><a href="https://blog.csdn.net/m0_46245938/article/details/104179209" target="_blank" rel="noopener">原文地址：</a></p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.jpg" alt="老苏叶 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.png" alt="老苏叶 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/%E7%BC%96%E7%A8%8B/" rel="tag"><i class="fa fa-tag"></i> 编程</a>
          
            <a href="/tags/Java/" rel="tag"><i class="fa fa-tag"></i> Java</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/04/23/%E6%96%87%E4%BB%B6%E5%B1%9E%E6%80%A7%E4%B8%8E%E6%96%87%E4%BB%B6%E6%9D%83%E9%99%90%E7%9A%84%E9%85%8D%E7%BD%AE/" rel="next" title="文件属性与文件权限的配置">
                <i class="fa fa-chevron-left"></i> 文件属性与文件权限的配置
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/04/24/Linux%E4%B8%8B%E7%94%A8%E6%88%B7%E5%92%8C%E7%BB%84%E7%9A%84%E7%AE%A1%E7%90%86/" rel="prev" title="Linux下用户和组的管理">
                Linux下用户和组的管理 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatra.jpg"
                alt="老苏叶" />
            
              <p class="site-author-name" itemprop="name">老苏叶</p>
              <p class="site-description motion-element" itemprop="description">狂热的代码爱好者卑微的菜鸟程序员</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives">
              
                  <span class="site-state-item-count">25</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">37</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">35</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/rss2.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/By-laosuye/By-laosuye.github.io.git" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="http://39.106.175.113" target="_blank" title="空间">
                      
                        <i class="fa fa-fw fa-vk"></i>空间</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="/qq" target="_blank" title="QQ">
                      
                        <i class="fa fa-fw fa-qq"></i>QQ</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="/weixin" target="_blank" title="微信">
                      
                        <i class="fa fa-fw fa-weixin"></i>微信</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Java基础知识点梳理"><span class="nav-text">Java基础知识点梳理</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#摘要："><span class="nav-text">摘要：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-Java简介"><span class="nav-text">1.Java简介</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-Java文件运行过程如下："><span class="nav-text">2.Java文件运行过程如下：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-Java语言基础语法"><span class="nav-text">3.Java语言基础语法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-注释"><span class="nav-text">1.注释</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-单行注释，语法如下："><span class="nav-text">1.单行注释，语法如下：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-多行注释，语法如下："><span class="nav-text">2.多行注释，语法如下：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-javadoc注释，是一种专业注释，可以被javadoc-exe工具解析提取生成帮助文档"><span class="nav-text">3.javadoc注释，是一种专业注释，可以被javadoc.exe工具解析提取生成帮助文档</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-标识符"><span class="nav-text">2.标识符</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-类的定义"><span class="nav-text">3.类的定义</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-Java数据类型"><span class="nav-text">4.Java数据类型</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-基本数据类型"><span class="nav-text">1.基本数据类型</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-整型表示方式"><span class="nav-text">2.整型表示方式</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-类型转换"><span class="nav-text">3.类型转换</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-复合数据类型"><span class="nav-text">4.复合数据类型</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#1-字符串-String"><span class="nav-text">1.字符串(String)</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#1-对字符串进行修改的常用方法有-包括格式化，大小写转换-："><span class="nav-text">1.对字符串进行修改的常用方法有(包括格式化，大小写转换)：</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#2-对字符串进行查找和替换的方法有："><span class="nav-text">2.对字符串进行查找和替换的方法有：</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#3-对字符串进行比较的方法有："><span class="nav-text">3.对字符串进行比较的方法有：</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#4-其他常见的方法比如统计长度，拼接，转换等："><span class="nav-text">4.其他常见的方法比如统计长度，拼接，转换等：</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-数组"><span class="nav-text">2.数组</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#1-数组可以用于存放固定大小的同类型元素，声明一个数组的语法如下："><span class="nav-text">1.数组可以用于存放固定大小的同类型元素，声明一个数组的语法如下：</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#2-创建数组的语法："><span class="nav-text">2.创建数组的语法：</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#3-数组的变量类型可以是前面介绍八种基本数据类型以及复合数据类型，“数组名-索引-”-可以访问数组元素，下面是一个操作一维数组例子："><span class="nav-text">3.数组的变量类型可以是前面介绍八种基本数据类型以及复合数据类型，“数组名[索引]” 可以访问数组元素，下面是一个操作一维数组例子：</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#4-操作二维数组的例子如下："><span class="nav-text">4.操作二维数组的例子如下：</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#5-java-util-Arrays类能方便地操作数组，它提供的所有方法都是静态的，比较常见的方法有："><span class="nav-text">5.java.util.Arrays类能方便地操作数组，它提供的所有方法都是静态的，比较常见的方法有：</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#6-使用Arrays的sort方法进行排序的例子如下："><span class="nav-text">6.使用Arrays的sort方法进行排序的例子如下：</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3-集合"><span class="nav-text">3.集合</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#4-类型转换方法"><span class="nav-text">4.类型转换方法</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#5-运算符"><span class="nav-text">5.运算符</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#1-算术运算符"><span class="nav-text">1.算术运算符</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-关系运算符"><span class="nav-text">2.关系运算符</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3-逻辑运算符"><span class="nav-text">3.逻辑运算符</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#4-位运算符"><span class="nav-text">4.位运算符</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#5-三目运算符"><span class="nav-text">5.三目运算符</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#6-控制语句"><span class="nav-text">6.控制语句</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#1-选择结构"><span class="nav-text">1.选择结构</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#1-if语句"><span class="nav-text">1.if语句</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#2-switch语句"><span class="nav-text">2.switch语句</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-循环结构"><span class="nav-text">2.循环结构</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#1-for语句"><span class="nav-text">1.for语句</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#2-while语句"><span class="nav-text">2.while语句</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#3-do…while-循环"><span class="nav-text">3.do…while 循环</span></a></li></ol></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#7-控制循环语句"><span class="nav-text">7.控制循环语句</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#1-break语句"><span class="nav-text">1.break语句</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-continue语句"><span class="nav-text">2.continue语句</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-Java变量类型"><span class="nav-text">5.Java变量类型</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-局部变量："><span class="nav-text">1.局部变量：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-实例变量-成员变量-："><span class="nav-text">2.实例变量(成员变量)：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-静态变量："><span class="nav-text">3.静态变量：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-不同类型变量在JVM中的存储情况如下表："><span class="nav-text">4.不同类型变量在JVM中的存储情况如下表：</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#1-方法-函数"><span class="nav-text">1.方法&#x2F;函数</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#1-方法语法"><span class="nav-text">1.方法语法</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-方法内存"><span class="nav-text">2.方法内存</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3-方法重载"><span class="nav-text">3.方法重载</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-面向对象"><span class="nav-text">6.面向对象</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-常用函数"><span class="nav-text">7.常用函数</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-输出函数"><span class="nav-text">1.输出函数</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-输入函数"><span class="nav-text">2.输入函数</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-总结"><span class="nav-text">8.总结</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#9-参考文献"><span class="nav-text">9.参考文献</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
       <div>
       <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?type=2&id=30431643&auto=1&height=66"></iframe>
       </div>

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">老苏叶</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">本站总字数&#58;</span>
    
    <span title="本站总字数">52.6k</span>
  
</div>









        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i> 访问人数
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i> 访问总量
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  










  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: true,
        appId: '4ePJvrPIyoMuyL54g1K6fNGc-gzGzoHsz',
        appKey: 'MKyiWYqHi0PIzxhH8jC1Q9pe',
        placeholder: '留下你的爪印吧～',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  
  

  

  
  

  

  

  

</body>
</html>
